<?php
include_once("../commonFunctions.php");
class Dealer {

    var $dealerCode;
    var $firstName;
    var $lastName;
    var $fullName;
    var $phone;
    var $isMA;
    var $isSuperMA;
    var $isAuditor;
    var $isSalesCoach;
    var $salesCoach;
    var $TTID = array();

    function __construct($dc = "") {
        // To protect MySQL injections************************************************************
        //$dc = stripslashes($userName);
        //$dc = mysql_real_escape_string($userName);
        $query = "select * from dealers where dealerCode='" . $dc . "';";
        $result = mysql_query($query) or die("query failed in Dealer.php");

        if (mysql_num_rows($result) > 0) {
            $row = mysql_fetch_array($result, MYSQL_ASSOC);
            if ($row['dealerCode'] == '' || $row['dealerCode'] == null) {
                return null;
            }
            $this->dealerCode = $row['dealerCode'];
            $this->firstName = ucfirst(strtolower($row['firstName']));
            $this->lastName = ucfirst(strtolower($row['lastName']));
            $this->fullName = $this->firstName . ' ' . $this->lastName;
            $this->phone = $row['phone'];
            $this->isMA = $row['isMA'];
            $this->isSuperMA = $row['isSuperMA'];
            $this->salesCoach = $row['salesCoach'];
            $this->isAuditor = $row['isAuditor'];
            $this->isSalesCoach = $row['isSalesCoach'];
        } else {
            return null; // return null, dealerCode doesn't exist
        }
    }

    function getTTStatusCount($status) {
        $query = 'select count(id) from tt where currentStatus = \'' . $status . '\' AND submittedBy=\'' . $this->dealerCode . '\'';
        $result = mysql_query($query) or die('query failed in Dealer.getUnresolvedCount()');
        $row = mysql_fetch_array($result, MYSQL_ASSOC);
        return $row['count(id)'];
    }

}

?>
